package com.xinyue.ext;

import com.xinyue.ext.data.EntityData;
import com.xinyue.ext.data.RootData;
import com.xinyue.ext.root.BeanRoot;
import com.xinyue.ext.root.ControllerRoot;
import com.xinyue.ext.root.DaoRoot;
import com.xinyue.ext.root.ServiceRoot;

public class RootBuilder {
	//私有构造器
	private RootBuilder() {
	}
	//私有内部类
	private static class SingletonHolder{
        private static RootBuilder instance = new RootBuilder();  
    }
	/***
	 * 获得实例对象
	 */
	public static RootBuilder getInstance() {
		return SingletonHolder.instance;
	}
	
	/**
	 * 创建符合freemarker的数据模型
	 * @param xmlDatas
	 * @return
	 */
	public RootData build(EntityData entity) {
		RootData data = new RootData();
		
		BeanRoot.getInstance().freemarkerData(entity, data);
		DaoRoot.getInstance().freemarkerData(entity, data);

		if(entity.isService()) {
			ServiceRoot.getInstance().freemarkerData(entity, data);
		}
		if(entity.isController()) {
			ControllerRoot.getInstance().freemarkerData(entity, data);
		}
		
		return data;
	}
}
